package main

import (
	"context"
	"errors"
	"fmt"
	"go.manyji.com/lib/hash"
	"go.manyji.com/lib/log"
	"go.manyji.com/lib/mysql"
	"go.manyji.com/lib/util/convert"
	"go.manyji.com/lib/util/rand"
	"sieve_agent_server/lib/server"
	"strconv"
	"strings"
	"time"
)

type mod_User struct{}

type mod_Recharge struct{}

type mod_IncomeStatistics struct{}

type mod_DailyRechargeStatistics struct{}

type mod_UserRecords struct{}

func GenPwdHash(pwd string) string {
	salt := hash.MD5([]byte(rand.RandStr(16) + time.Now().String()))
	return hash.SHA256([]byte(pwd+salt)) + salt
}

/*	========================================================================= 用户管理相关接口 ========================================================================= */

func (a *mod_User) getDefaultSieveSourceConfig(ctx *server.Context) ([]string, error) {

	var (
		querySQL = fmt.Sprintf(`
			SELECT
				business_type_configuration.*
			FROM
			    sieve_source_config
			INNER JOIN 
			    business_type_configuration ON business_type_configuration.sieve_source_config_id = sieve_source_config.id AND business_type_configuration.deleted = 0
			WHERE %v AND sieve_source_config.deleted = 0 
`, "`default` = 1")
	)

	resp, err := db.QueryRaw(context.Background(), querySQL, BusinessTypeConfiguration{})
	if err != nil {
		return nil, err
	}

	var (
		cids      []string
		removeDup = map[uint64]struct{}{}
	)
	// 如果有多个相同的 business_type_configuration.id 做去重处理
	for _, v := range resp {
		vv := v.(*BusinessTypeConfiguration)
		if _, ok := removeDup[vv.ID]; ok {
			continue
		}
		removeDup[vv.ID] = struct{}{}
	}

	for v := range removeDup {
		cids = append(cids, fmt.Sprintf("%v", v))
	}

	return cids, nil
}

func (a *mod_User) GetRoleID(ctx context.Context, userId uint64) (uint64, error) {

	var (
		querySQL = fmt.Sprintf(`
		SELECT
			*
		FROM
		    user
		WHERE
		    id = %v AND deleted = 0
`, userId)
	)

	resp, err := db.QueryRaw(ctx, querySQL, User{})
	if err != nil {
		return 0, err
	}
	if len(resp) <= 0 {
		return 0, errors.New(fmt.Sprintf("no found such role by user_id:%+v", userId))
	}

	return resp[0].(*User).RoleId, nil
}

func (a *mod_User) API_add_item(ctx *server.Context) interface{} {

	var (
		uid  = uint64(ctx.Uid)
		now  = time.Now().Unix()
		item = map[string]interface{}{
			"creator":    uid,
			"create_at":  now,
			"updated_at": now,
		}
		c = context.Background()
	)

	if ctx.Args.Has("account") && ctx.Args.Get("account") != "" {
		item["account"] = ctx.Args.Get("account")
	} else {
		return errors.New("请填写'账号'")
	}

	if ctx.Args.Has("tag") && ctx.Args.Get("tag") != "" {
		item["tag"] = ctx.Args.Get("tag")
	}

	if ctx.Args.Has("account") && ctx.Args.Get("account") != "" {
		item["passwd"] = ctx.Args.Get("passwd")
	} else {
		return errors.New("请填写'密码'")
	}

	if ctx.Args.Has("business_price_id") && ctx.Args.Get("business_price_id") != "" {
		item["business_price_id"] = ctx.Args.Get("business_price_id")
		if id, err := strconv.ParseUint(ctx.Args.Get("business_price_id"), 10, 64); err != nil {
			return errors.New("请填写'价格方案'")
		} else {
			item["business_price_id"] = id
		}
	} else {
		return errors.New("请填写'价格方案'")
	}

	item["role_id"] = (&data_Role{}).GetChannelAgentRole().ID
	item["leader_id"] = uid

	if respUser, err := (&data_User{}).GetByName(c, item["account"].(string)); err == nil && respUser != nil {
		return errors.New(fmt.Sprintf("用户已存在"))
	}

	respUserInfo, _ := (&data_User{}).GetUserInfoByUID(c, uid, false)
	if respUserInfo != nil {
		item["top_leader_id"] = respUserInfo.LeaderId
	}

	var (
		logType = "业务日志"
		logName = "创建用户"
		logMsg  string
	)

	defer func() {
		go func() {
			userInfo := User{
				Account: item["account"].(string),
				Creator: int64(uid),
			}
			log.Info(fmt.Sprintf("创建用户 %+v", (&data_User{}).CreateBusinessRecord(c, userInfo, logType, logName, logMsg)))
			if v, ok := item["business_price_id"]; ok {
				log.Info(fmt.Sprintf("更新业务方案用户数量 %+v", (&data_User{}).UpdateBusinessPriceUserCount(c, v.(uint64), false)))
			}
		}()
	}()

	ids, err := a.getDefaultSieveSourceConfig(ctx)
	if err != nil {
		return err
	} else {
		item["business_type_ids"] = strings.Join(ids, "|")
	}

	item["passwd"] = GenPwdHash(item["passwd"].(string))
	_, err = db.Create(c, "user", item)
	if err != nil {
		logType = "异常日志"
		logMsg = err.Error()
	}

	return err
}

func (a *mod_User) API_query_list(ctx *server.Context) interface{} {

	var (
		pageSize       = 99999
		pageIndex      = 1
		c              = context.Background()
		queryCondition []string
		onlyCount      bool
	)
	if ctx.Args.Has("page_size") && ctx.Args.Get("page_size") != "" {
		pageSize = convert.Atoi(ctx.Args.Get("page_size"))
	}

	if ctx.Args.Has("page_index") && ctx.Args.Get("page_index") != "" {
		pageIndex = convert.Atoi(ctx.Args.Get("page_index"))
	}

	if ctx.Args.Has("account") && ctx.Args.Get("account") != "" {
		queryCondition = append(queryCondition, fmt.Sprintf(" account LIKE %v", "'%"+ctx.Args.Get("account")+"%'"))
	}

	if ctx.Args.Has("status") && ctx.Args.Get("status") != "" {
		queryCondition = append(queryCondition, fmt.Sprintf(" status = %v", ctx.Args.Get("status")))
	}

	if ctx.Args.Has("only_count") && ctx.Args.Get("only_count") != "" {
		onlyCount = convert.Atoi(ctx.Args.Get("only_count")) == 1
	}

	if ctx.Args.Has("business_price_id") && ctx.Args.Get("business_price_id") != "" {
		if len(strings.Split(ctx.Args.Get("business_price_id"), ",")) > 1 {
			queryCondition = append(queryCondition, fmt.Sprintf(" business_price_id IN (%v)", ctx.Args.Get("business_price_id")))
		} else {
			queryCondition = append(queryCondition, fmt.Sprintf(" business_price_id = %v", ctx.Args.Get("business_price_id")))
		}
	}

	if (ctx.Args.Has("start") && ctx.Args.Get("start") != "") && (ctx.Args.Has("end") && ctx.Args.Get("end") != "") {
		start, end := convert.Atoi(ctx.Args.Get("start")), convert.Atoi(ctx.Args.Get("end"))
		queryCondition = append(queryCondition, fmt.Sprintf("(create_at >= %v && create_at <= %v)", start, end))
	}

	defCondition := []string{
		"user.deleted = 0",
		fmt.Sprintf("user.role_id = %v", (&data_Role{}).GetChannelAgentRole().ID),
		fmt.Sprintf("user.leader_id = %v", ctx.Uid),
	}
	queryCondition = append(queryCondition, defCondition...)

	var (
		condition = fmt.Sprintf(`
 WHERE %v `, strings.Join(queryCondition, " AND "))
		queryCountSQL = fmt.Sprintf(`
	SELECT 
	    COUNT(*)  as count
	FROM 
	    user
	LEFT JOIN 
    	business_price_scheme ON business_price_scheme.id = user.business_price_id and business_price_scheme.deleted = 0
		%v
`, condition)
		querySQL = fmt.Sprintf(`
SELECT
  user.id AS id,
  user.tag AS tag,
  user.account AS account,
  user.passwd AS passwd,
  user.business_price_id as business_price_id,
  business_price_scheme.name as business_price_name,
  business_price_scheme.description as business_price_desc,
  user.status AS status,
  user.role_id AS role_id,
  user.leader_id AS leader_id,
  user.recharge_points AS recharge_points,
  user.bonus_points AS bonus_points,
  user.points_consume_account AS points_consume_account,
  user.points_consume_gift AS points_consume_gift,
  user.create_at AS create_at,
  user.updated_at AS updated_at,
  user.deleted AS deleted
FROM 
    user
LEFT JOIN 
    business_price_scheme ON business_price_scheme.id = user.business_price_id and business_price_scheme.deleted = 0
%v 	ORDER BY create_at DESC %v 
`, condition, fmt.Sprintf(" LIMIT %v OFFSET %v", pageSize, (pageIndex-1)*pageSize))
	)

	log.Info("query count ", queryCountSQL)
	respCount, err := db.QueryRaw(c, queryCountSQL, QueryCount{})
	if err != nil {
		return err
	}

	if respCount == nil {
		return nil
	}

	count := respCount[0].(*QueryCount).Count

	if onlyCount {
		return map[string]interface{}{
			"total": count,
		}
	}

	respTaskList, err := db.QueryRaw(c, querySQL, UserQueryRsp1{})
	if err != nil {
		return err
	}

	ret := map[string]interface{}{
		"list":  respTaskList,
		"total": count,
	}
	return ret
}

func (a *mod_User) API_enable_item(ctx *server.Context) interface{} {

	var (
		now        = time.Now().Unix()
		updateKeys = map[string]interface{}{
			"updated_at": now,
			"status":     1,
		}
		queryKeys = map[string]interface{}{}
	)
	if ctx.Args.Has("id") && ctx.Args.Get("id") != "" {
		if id, err := strconv.ParseUint(ctx.Args.Get("id"), 10, 64); err != nil {
			return errors.New("请求参数错误")
		} else {
			queryKeys["id"] = id
		}
	} else {
		return errors.New("请填写'账号'")
	}

	if err := db.Update(context.Background(), "user", updateKeys, queryKeys); err != nil {
		log.Err(fmt.Sprintf("update user status err:%+v", err))
		return err
	}

	return nil
}

func (a *mod_User) API_disable_item(ctx *server.Context) interface{} {

	var (
		now        = time.Now().Unix()
		updateKeys = map[string]interface{}{
			"updated_at": now,
			"status":     2,
		}
		queryKeys = map[string]interface{}{}
	)
	if ctx.Args.Has("id") && ctx.Args.Get("id") != "" {
		if id, err := strconv.ParseUint(ctx.Args.Get("id"), 10, 64); err != nil {
			return errors.New("请求参数错误")
		} else {
			queryKeys["id"] = id
		}
	} else {
		return errors.New("请求参数缺失")
	}

	if err := db.Update(context.Background(), "user", updateKeys, queryKeys); err != nil {
		log.Err(fmt.Sprintf("update user status err:%+v", err))
		return err
	}

	return nil
}

func (a *mod_User) API_edit_item(ctx *server.Context) interface{} {

	var (
		now        = time.Now().Unix()
		updateKeys = map[string]interface{}{
			"updated_at": now,
		}
		queryKeys = map[string]interface{}{}
	)

	// 批量接口，批量调整
	if ctx.Args.Has("ids") && ctx.Args.Get("ids") != "" {

		ids := ctx.Args.Get("ids")
		ctx.Args.Del("ids")
		for _, v := range strings.Split(ids, "|") {
			ctx.Args.Set("id", v)
			a.API_edit_item(ctx)
		}
	}

	if ctx.Args.Has("id") && ctx.Args.Get("id") != "" {
		if id, err := strconv.ParseUint(ctx.Args.Get("id"), 10, 64); err != nil {
			return errors.New("请求参数错误")
		} else {
			queryKeys["id"] = id
		}
	} else {
		return errors.New("请求参数缺失")
	}

	if ctx.Args.Has("account") && ctx.Args.Get("account") != "" {
		updateKeys["account"] = ctx.Args.Get("account")
	}

	if ctx.Args.Has("account") && ctx.Args.Get("account") != "" {
		updateKeys["account"] = ctx.Args.Get("account")
	}

	if ctx.Args.Has("tag") && ctx.Args.Get("tag") != "" {
		updateKeys["tag"] = ctx.Args.Get("tag")
	}

	fUpdate := func() error {
		if err := db.Update(context.Background(), "user", updateKeys, queryKeys); err != nil {
			log.Err(fmt.Sprintf("update user status err:%+v", err))
			return err
		}
		return nil
	}

	if ctx.Args.Has("business_price_id") && ctx.Args.Get("business_price_id") != "" {

		if id, err := strconv.ParseUint(ctx.Args.Get("business_price_id"), 10, 64); err != nil {
			return errors.New("请求参数错误")
		} else {
			updateKeys["business_price_id"] = id
		}

		item := map[string]interface{}{
			"business_price_id": updateKeys["business_price_id"],
		}

		if err := (&data_User{}).updateBizPricesUserCount(context.Background(), queryKeys["id"].(uint64), item, fUpdate); err != nil {
			log.Err(fmt.Sprintf("更新业务方案配置的用户数量失败:%+v", err))
			return err
		}

		return nil
	}

	return fUpdate()
}

func (a *mod_User) API_resetPasswd_item(ctx *server.Context) interface{} {

	var (
		now        = time.Now().Unix()
		updateKeys = map[string]interface{}{
			"updated_at": now,
		}
		queryKeys = map[string]interface{}{}
	)

	if ctx.Args.Has("id") && ctx.Args.Get("id") != "" {
		if id, err := strconv.ParseUint(ctx.Args.Get("id"), 10, 64); err != nil {
			return errors.New("请求参数错误")
		} else {
			queryKeys["id"] = id
		}
	} else {
		return errors.New("请求参数缺失")
	}

	if ctx.Args.Has("passwd") && ctx.Args.Get("passwd") != "" {
		updateKeys["passwd"] = GenPwdHash(ctx.Args.Get("passwd"))
	} else {
		return errors.New("请填写要重置的密码")
	}

	if err := db.Update(context.Background(), "user", updateKeys, queryKeys); err != nil {
		log.Err(fmt.Sprintf("update user status err:%+v", err))
		return err
	}

	return nil
}

func (a *mod_User) API_del_item(ctx *server.Context) interface{} {

	var (
		id uint64
		c  = context.Background()
	)
	if ctx.Args.Has("id") && ctx.Args.Get("id") != "" {
		if _id, err := strconv.ParseUint(ctx.Args.Get("id"), 10, 64); err != nil {
			return errors.New("请求参数错误")
		} else {
			id = _id
		}
	} else {
		return errors.New("请求参数缺失")
	}

	var oldBizPriceId uint64
	if respUserInfo, _ := (&data_User{}).GetUserInfoByUID(c, id, false); respUserInfo != nil {
		oldBizPriceId = respUserInfo.BusinessPriceId
	}

	return db.TransactionTx(c, func(ctx context.Context, t *mysql.Tx) error {

		if err := (&data_User{}).UpdateBusinessPriceUserCount(c, oldBizPriceId, true); err != nil {
			return err
		}

		return db.SoftDelete(context.Background(), "user", id)
	})
}

/*	========================================================================= 用户管理相关接口 ========================================================================= */

/*	========================================================================= 用户管理相关接口 ========================================================================= */

/*	========================================================================= 充值管理相关接口 ========================================================================= */

func (a *mod_Recharge) API_add_item(ctx *server.Context) interface{} {

	var (
		reqArgs = map[string]interface{}{}
	)

	if ctx.Args.Has("account_id") && ctx.Args.Get("account_id") != "" {
		reqArgs["account_id"], _ = strconv.ParseUint(ctx.Args.Get("account_id"), 10, 64)
	} else {
		return errors.New("请填写'充值账户'")
	}

	if ctx.Args.Has("recharge_points") && ctx.Args.Get("recharge_points") != "" {
		reqArgs["recharge_points"], _ = strconv.ParseUint(ctx.Args.Get("recharge_points"), 10, 64)
	}

	if ctx.Args.Has("bonus_points") && ctx.Args.Get("bonus_points") != "" {
		reqArgs["bonus_points"], _ = strconv.ParseUint(ctx.Args.Get("bonus_points"), 10, 64)
	}

	if ctx.Args.Has("refund_points") && ctx.Args.Get("refund_points") != "" {
		reqArgs["refund_points"], _ = strconv.ParseUint(ctx.Args.Get("refund_points"), 10, 64)
	}
	if ctx.Args.Has("type") && ctx.Args.Get("type") != "" {
		reqArgs["type"] = uint64(convert.Atoi(ctx.Args.Get("type")))
	}

	return (&data_Recharge{}).Create(context.Background(), uint64(ctx.Uid), reqArgs)
}

func (a *mod_Recharge) API_query_list(ctx *server.Context) interface{} {

	var (
		pageSize       = 30
		pageIndex      = 1
		pp             = PaginationParam{}
		queryCondition []string
	)

	if (ctx.Args.Has("start") && ctx.Args.Get("start") != "") && (ctx.Args.Has("end") && ctx.Args.Get("end") != "") {
		start, end := convert.Atoi(ctx.Args.Get("start")), convert.Atoi(ctx.Args.Get("end"))
		queryCondition = append(queryCondition, fmt.Sprintf("(recharge.create_at >= %v && recharge.create_at <= %v)", start, end))
	}

	if ctx.Args.Has("account_id") && ctx.Args.Get("account_id") != "" {
		queryCondition = append(queryCondition, fmt.Sprintf("recharge.account_id = %v", ctx.Args.Get("account_id")))
	}

	if ctx.Args.Has("page_index") && ctx.Args.Get("page_index") != "" {
		pageIndex = convert.Atoi(ctx.Args.Get("page_index"))
	}

	if ctx.Args.Has("page_size") && ctx.Args.Get("page_size") != "" {
		pageSize = convert.Atoi(ctx.Args.Get("page_size"))
	}
	pp.PageIndex = pageIndex
	pp.PageSize = pageSize

	return (&data_Recharge{}).Query(context.Background(), uint64(ctx.Uid), pp, queryCondition)
}

func (a *mod_Recharge) API_export_list(ctx *server.Context) interface{} {

	var (
		reqArgs = map[string]interface{}{}
	)

	/*
		1. recharge 表的主键ID，多个 用 "|" 拼接
		2.当前查询条件下的顺序ID，多个 用 "|" 拼接
	*/

	if ctx.Args.Has("ids") && ctx.Args.Get("ids") != "" {
		reqArgs["ids"] = ctx.Args.Get("ids")
	}

	if ctx.Args.Has("seqs") && ctx.Args.Get("seqs") != "" {
		reqArgs["seqs"] = ctx.Args.Get("seqs")
	}

	return (&data_Recharge{}).Export(context.Background(), reqArgs)
}

/*	========================================================================= 充值管理相关接口 ========================================================================= */

/*	========================================================================= 收益统计相关接口 ========================================================================= */

func (a *mod_IncomeStatistics) API_query_list(ctx *server.Context) interface{} {

	var (
		pageSize       = 30
		pageIndex      = 1
		pp             = PaginationParam{}
		queryCondition []string
	)

	if ctx.Args.Has("date") && ctx.Args.Get("date") != "" {

		queryDates := strings.Split(ctx.Args.Get("date"), ",")
		if len(queryDates) == 1 {
			queryCondition = append(queryCondition, fmt.Sprintf("date = '%v'", queryDates[0]))
		}
		if len(queryDates) == 2 {
			queryCondition = append(queryCondition, fmt.Sprintf("date >= '%v' AND date <= '%v'", queryDates[0], queryDates[1]))
		}
	}

	if ctx.Args.Has("business_type_id") && ctx.Args.Get("business_type_id") != "" {
		bizTyID := uint64(convert.Atoi(ctx.Args.Get("business_type_id")))
		queryCondition = append(queryCondition, fmt.Sprintf("business_type_id = %v", bizTyID))
	}

	if ctx.Args.Has("account_id") && ctx.Args.Get("account_id") != "" {
		id := convert.Atoi(ctx.Args.Get("account_id"))
		queryCondition = append(queryCondition, fmt.Sprintf("account_id = %v", id))
	}

	if ctx.Args.Has("sieve_source_name") && ctx.Args.Get("sieve_source_name") != "" {
		queryCondition = append(queryCondition, fmt.Sprintf(" sieve_source_name = '%v'", ctx.Args.Get("sieve_source_name")))
	}

	if ctx.Args.Has("page_index") && ctx.Args.Get("page_index") != "" {
		pageIndex = convert.Atoi(ctx.Args.Get("page_index"))
	}

	if ctx.Args.Has("page_size") && ctx.Args.Get("page_size") != "" {
		pageSize = convert.Atoi(ctx.Args.Get("page_size"))
	}
	pp.PageIndex = pageIndex
	pp.PageSize = pageSize

	return (&data_IncomeStatistics{}).Query(context.Background(), uint64(ctx.Uid), pp, queryCondition)
}

func (a *mod_IncomeStatistics) API_export_list(ctx *server.Context) interface{} {

	var (
		data = map[string]interface{}{}
	)

	if ctx.Args.Has("ids") && ctx.Args.Get("ids") != "" {
		data["ids"] = ctx.Args.Get("ids")
	} else {
		return errors.New("请求参数缺失")
	}

	return (&data_IncomeStatistics{}).Export(context.Background(), uint64(ctx.Uid), data)
}

/*	========================================================================= 收益统计相关接口 ========================================================================= */

/*	========================================================================= 日充值统计相关接口 ========================================================================= */

func (a *mod_DailyRechargeStatistics) API_query_list(ctx *server.Context) interface{} {

	var (
		pageSize       = 30
		pageIndex      = 1
		pp             = PaginationParam{}
		queryCondition []string
	)

	if ctx.Args.Has("date") && ctx.Args.Get("date") != "" {

		queryDates := strings.Split(ctx.Args.Get("date"), ",")
		if len(queryDates) == 1 {
			queryCondition = append(queryCondition, fmt.Sprintf("date = '%v'", queryDates[0]))
		}
		if len(queryDates) == 2 {
			queryCondition = append(queryCondition, fmt.Sprintf("date >= '%v' AND date <= '%v'", queryDates[0], queryDates[1]))
		}
	}

	pp.PageIndex = pageIndex
	pp.PageSize = pageSize

	return (&data_DailyRechargeStatistics{}).Query(context.Background(), uint64(ctx.Uid), pp, queryCondition)
}

func (a *mod_DailyRechargeStatistics) API_export_list(ctx *server.Context) interface{} {

	var (
		data = map[string]interface{}{}
	)

	if ctx.Args.Has("ids") && ctx.Args.Get("ids") != "" {
		data["ids"] = ctx.Args.Get("ids")
	} else {
		return errors.New("请求参数缺失")
	}

	return (&data_DailyRechargeStatistics{}).Export(context.Background(), data)
}

/*	========================================================================= 日充值统计相关接口 ========================================================================= */

/*	========================================================================= 用户操作记录相关接口 ========================================================================= */

func (a *mod_UserRecords) API_query_list(ctx *server.Context) interface{} {

	var (
		pageSize       = 30
		pageIndex      = 1
		pp             = PaginationParam{}
		queryCondition []string
	)

	if (ctx.Args.Has("start") && ctx.Args.Get("start") != "") && (ctx.Args.Has("end") && ctx.Args.Get("end") != "") {
		start, end := convert.Atoi(ctx.Args.Get("start")), convert.Atoi(ctx.Args.Get("end"))
		queryCondition = append(queryCondition, fmt.Sprintf("(user_op_record.create_at >= %v && user_op_record.create_at <= %v)", start, end))
	}

	if ctx.Args.Has("status") && ctx.Args.Get("status") != "" {
		queryCondition = append(queryCondition, fmt.Sprintf(" user_op_record.status = %v", ctx.Args.Get("status")))
	}

	if ctx.Args.Has("op_type_name") && ctx.Args.Get("op_type_name") != "" {
		queryCondition = append(queryCondition, fmt.Sprintf(" user_op_record.op_type_name = '%v'", ctx.Args.Get("op_type_name")))
	}

	if ctx.Args.Has("business_type_name") && ctx.Args.Get("business_type_name") != "" {
		queryCondition = append(queryCondition, fmt.Sprintf(" user_op_record.business_type_name = '%v'", ctx.Args.Get("business_type_name")))
	}

	if ctx.Args.Has("sieve_source_name") && ctx.Args.Get("sieve_source_name") != "" {
		queryCondition = append(queryCondition, fmt.Sprintf(" user_op_record.sieve_source_name = '%v'", ctx.Args.Get("sieve_source_name")))
	}

	if ctx.Args.Has("creator") && ctx.Args.Get("creator") != "" {
		queryCondition = append(queryCondition, fmt.Sprintf(" user_op_record.creator = %v", ctx.Args.Get("creator")))
	}

	pp.PageIndex = pageIndex
	pp.PageSize = pageSize

	return (&data_UserRecords{}).Query(context.Background(), uint64(ctx.Uid), pp, queryCondition)
}

func (a *mod_UserRecords) API_export_list(ctx *server.Context) interface{} {

	var (
		data = map[string]interface{}{}
	)

	if ctx.Args.Has("ids") && ctx.Args.Get("ids") != "" {
		data["ids"] = ctx.Args.Get("ids")
	} else {
		return errors.New("请求参数缺失")
	}

	return (&data_UserRecords{}).Export(context.Background(), data)
}

/*	========================================================================= 用户操作记录相关接口 ========================================================================= */
